package org.libraq.basic.service.impl;

import org.libraq.basic.mapper.BaseMapper;
import org.libraq.basic.query.BaseQuery;
import org.libraq.basic.service.IBaseService;
import org.libraq.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return mapper.findById(id);
    }


    @Override
    public PageList<T> findByQuery(BaseQuery query) {
        Long total = mapper.findTotal(query);
        List<T> byQuery = mapper.findByQuery(query);
        return new PageList<T>(byQuery,total);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public void save(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void patchDel(List<Long> ids) {
        mapper.patchDel(ids);
    }
}
